jQuery(document).ready(function () {
    selectProductList();
    $("#resetBtn").on("click",function () {
        $("#productName").val("");
        $("#productId").val("");
        $("#author").val("");
        $("#press").val("");
        $("#type").val("");
        $("#state").val("");
        $("#startTime").val("");
        $("#endTime").val("");
    });
});
function queryParams(params) {
    return getQueryParams(params, "searchForm");
}
function selectProductList() {
    $('#productTable').bootstrapTable("destroy");
    $('#productTable').bootstrapTable({
        method: "post",
        url: rootPath+"/productManage/ajax/getProductList",
        showExport : true,
        exportTypes: ['excel'],//['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
        Icons:'glyphicon-export',
        exportOptions:{
            ignoreColumn: [0],  //忽略某一列的索引
            fileName: '库存列表',  //文件名称设置
            worksheetName: 'sheet1',  //表格工作区名称
            tableName: '库存列表'
        },
        exportDataType : 'all'
    });
}
function addStock() {
    var selections = $('#productTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    var productId = selections[0].product_id;
    layer.prompt({title:"请填入增加的数量(/个)：", formType: 3}, function(text, index){
       if (text < 1){
            commonJs.alertMsg("增加数量不可小于1，请重新填写！",function () {
                layer.close(index);
            })
        }else {
            commonJs.ajaxRequest(rootPath+"/productManage/ajax/addStock",{
                productId:productId,
                addCount:text
            },function(data){
                if(data.code == '0000'){
                    commonJs.alertMsg("增加成功",function(){
                        $("#productTable").bootstrapTable("refresh");
                        layer.close(index);
                    })
                }else {
                    layer.msg(data.msg);
                }
            })
        }
    });
}